var api = require('../../utils/api.js');



Page({

    /**
     * 页面的初始数据
     */
    data: {
        lists:[],
        page:1,
        title:''
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that=this;
        this.setData({
            id:options.id
        })



        this.getall();
    },

    seeinfo(ret){
        console.log(ret.currentTarget.dataset.code);
        wx.navigateTo({
     
          url: '/pages/about/update?code='+ret.currentTarget.dataset.code,
        })
       
    },

    addlogs(ret){
        console.log();
        var id=ret.currentTarget.dataset.id;
        var tid=this.data.id;
        var that=this;

        wx.showModal({
          title: '确认删除',
          content: '确认删除,并修改状态',
          complete: (res) => {
      
        
            if (res.confirm) {
              
                api.post({
                    url: 'kuaidi/backgoodtocode',
                    data: {id:id},
                    success: data => {
                       
                        api.post({
                            url: 'kuaidi/getinfobyid',
                            data: {id:tid},
                            success: data => {
                               
                                that.setData({
                                    title:data.data.order
                                })
                            }
                        })
                
                        that.getall();
                    }
                })
        
                
            }
          }
        })

    },

    getall(){
        var that=this;
        api.post({
            url: 'kuaidi/getalllistbykid',
            data: {kid:this.data.id},
            success: data => {

               
                that.setData({
                    lists:data.data
                })
            }
        })
    },

    scanCodeEvent: function(){
        var that = this;
        wx.scanCode({
          onlyFromCamera: true,// 只允许从相机扫码
          success(res){
            JSON.stringify(res)
            console.log(res.result)
            
            api.post({
                url: 'kuaidi/getgoodsbyid',
                data: {code:res.result},
                success: data => {

                    if(data.code!=1){
                        wx.showToast({
                          title: data.msg,
                          icon:'none'
                        })
                    }else{
                        wx.showModal({
                          title: '请确认',
                          content: '确认产品信息:'+data.data.color +data.data.title,
                          complete: (res) => {
                         
                            if (res.confirm) {
                              that.chuku(data.data.id);
                            }
                          }
                        })
                    }


                   
                    console.log(data);
                }
            })
     
          },
          fail(ret){
            console.log(ret);
            wx.showToast({
              title: ret.errMsg,
              icon:'none'
            })
          }
        })
      },

      chuku(id){
        var that=this;
        var kid=this.data.id;
        api.post({
            url: 'kuaidi/chuku',
            data: {id:id,kid:kid},
            success: data => {
                wx.showToast({
                  title: data.msg,
                  icon:'none'
                })
            that.getall();
            }
        })
      }

})